package com.hexinfo.dmpro.component.comparison.entity;

import lombok.Data;

/**
 * @Package com.hexinfo.dmpro.component.comparison.entity
 * @ClassName TableContrastParamEntity
 * @Description 表比对任务 需要的参数 的封装类
 * @Author Huang Yanyihe
 * @Date 2023/9/10 21:29
 * @Version v1.0
 **/
@Data
public class TableContrastParamEntity {

    // 对比类型(热备数据对比,冷备数据对比)
    private String contrastType = "WARM";

    // 比对任务唯一标识
    private String tableFlag;

    //源库名
    private String sourceDbName;

    //源表名
    private String sourceTableName;

    // 源表查询条件 （默认为空）
    private String sourceQueryCriteria = "";

    //比对库名
    private String targetDbName;

    //比对表名
    private String targetTableName;

    // 源表查询条件 （默认为空）
    private String targetQueryCriteria = "";

    public String getTableFlag() {
        return sourceDbName + "." + sourceTableName + " " + getSourceQueryCriteria();
    }

    //获取源库.源表名
    public String getSourceDbAndTableName() {
        return sourceDbName + "." + sourceTableName;
    }

    //获取目标库.目标表名
    public String getTargetDbAndTableName() {
        return targetDbName + "." + targetTableName;
    }

    /**
     * @Method getSourceQueryCriteria
     * @Return java.lang.String
     * @Description 获取源表查询条件
     * @Author Huang Yanyihe
     * @Date 2023/9/18 17:26
     * @Version V1.0
     */
    public String getSourceQueryCriteria() {
        if (sourceQueryCriteria.equals("")) {
            return "";
        }
        String prefix = sourceQueryCriteria.trim().substring(0, 5);
        if ("where".equals(prefix.toLowerCase())) {
            return sourceQueryCriteria;
        }
        return "where " + sourceQueryCriteria;
    }

    /**
     * @Method getTargetQueryCriteria
     * @Return java.lang.String
     * @Description 获取目标表查询条件
     * @Author Huang Yanyihe
     * @Date 2023/9/18 17:26
     * @Version V1.0
     */
    public String getTargetQueryCriteria() {
        if (targetQueryCriteria.equals("")) {
            return "";
        }
        String prefix = targetQueryCriteria
                .trim().substring(0, 5);
        if ("where".equals(prefix.toLowerCase())) {
            return targetQueryCriteria;
        }
        return "where " + targetQueryCriteria;
    }
}
